//
//  DateExt.swift
//  AIImage
//
//  Created by deng on 2023/12/10.
//

import UIKit

enum DateFormatType:String {
    case day = "yyyy-MM-dd"
    case hour = "yyyy-MM-dd HH"
    case minute = "yyyy-MM-dd HH:mm"
    case second = "yyyy-MM-dd HH:mm:ss"
    case img = "yyyyMMddHHmmssSSS"
}

extension Date {
    public func dateUploadIMG() -> String {
        
        return dateFormatNormal(formatStyle: "yyyyMMddHHmmssSSS")
    }
    
    public func dateStringWithYearMonthAndDay() -> String {
        
        return dateFormatNormal(formatStyle: "yyyy-MM-dd HH:mm:ss")
    }
    

    static func getCurrentDate(type:DateFormatType) -> String{
        
        let dateFormat = DateFormatter.init()
        dateFormat.dateFormat = type.rawValue
        let date = Date()
        return dateFormat.string(from: date)
    }
    
    public func dateFormatNormal(formatStyle : String) -> String {
        let dateFormat = DateFormatter()
        dateFormat.timeZone = TimeZone.init(identifier: "Asia")
        dateFormat.locale = Locale.init(identifier: "zh_CN")
        dateFormat.dateFormat = formatStyle
        return dateFormat.string(from: self)
    }
    
    public func dateStrFormat(time:String,formatStyle : String) -> Date {
        let dateFormat = DateFormatter()
        dateFormat.timeZone = TimeZone.init(identifier: "Asia")
        dateFormat.locale = Locale.init(identifier: "zh_CN")
        dateFormat.dateFormat = formatStyle
        return dateFormat.date(from: time) ?? Date()
    }
}
